<template>
	<view class="content">
		<textarea class="textareas" maxlength="-1" v-model.trim="searchData.codes" :confirm-hold="true"
			confirm-type="return" placeholder="请输入柜号，多个编码之间以换行拼接，禁止输入特殊字符！最多30个设备号" placeholder-style="font-size:28rpx"
			:rows="6" @change.native="keyUp($event)" @input.native="keyInput($event)"
			@blur.native="keyBlur($event)"></textarea>
		<view class="search_btns">
			<button type="primary" size="mini" @click="doSearch">搜索</button>
		</view>

		<!-- 换电柜参数 -->
		<view class="param-content">
			<view v-if="equipTypeCode == 'EC'">
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check1')">
						<checkbox :checked="checkList.check1" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>快充</text>
					<switch color="#51b7b9" @change="switchChange($event,'06010014')" :checked="boxForm['06010014']"
						style="transform:scale(0.7)" />
				</view>
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check2')">
						<checkbox :checked="checkList.check2" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>备电</text>
					<switch color="#51b7b9" :checked="boxForm['06010015']" @change="switchChange($event,'06010015')"
						style="transform:scale(0.7)" />
				</view>
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check3')">
						<checkbox :checked="checkList.check3" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>整流单元休眠</text>
					<switch color="#51b7b9" :checked="boxForm['06010023']" @change="switchChange($event,'06010023')"
						style="transform:scale(0.7)" />
				</view>
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check4')">
						<checkbox :checked="checkList.check4" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>电子锁反馈类型</text>
					<uni-data-select class="sliders" placeholder="请选择电子锁反馈类型" v-model="boxForm['06010007']"
						:localdata="getLockOption"></uni-data-select>
				</view>
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check5')">
						<checkbox :checked="checkList.check5" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>门轴</text>
					<uni-data-select class="sliders" style="width: 50%;" placeholder="请选择门轴"
						:disabled="!boxForm['06010008'] || isShow" v-model="boxForm['06010009']"
						:localdata="getLockOption">
					</uni-data-select>
					<switch color="#51b7b9" :checked="boxForm['06010008']" @change="switchChange($event,'06010008')"
						style="transform:scale(0.7)" />
				</view>
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check6')">
						<checkbox :checked="checkList.check6" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>电池在位模式</text>
					<uni-data-select class="sliders" placeholder="请选择电池在位模式" v-model="boxForm['06010011']"
						:localdata="batteryIsOn"></uni-data-select>
				</view>
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check7')">
						<checkbox :checked="checkList.check7" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>灭火器反馈类型</text>
					<uni-data-select class="sliders" placeholder="请选择灭火器反馈类型" v-model="boxForm['06010022']"
						:localdata="getLockOption"></uni-data-select>
				</view>
				
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check8')">
						<checkbox :checked="checkList.check8" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>主控2.0/3.0版本</text>
					<uni-data-select class="sliders" placeholder="请选择主控2.0/3.0版本" v-model="boxForm['06010006']"
						:localdata="mainControlVersion"></uni-data-select>
				</view>
				
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check9')">
						<checkbox :checked="checkList.check9" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>消防模式</text>
					<uni-data-select class="sliders" placeholder="请选择消防模式" v-model="boxForm['06010024']"
						:localdata="getLockOption"></uni-data-select>
				</view>
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check10')">
						<checkbox :checked="checkList.check10" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>系统启动散热温度</text>
					<input v-model="boxForm['06010016']" class="uni-input" type="digit"
						@input="onKeyInput($event,'06010016')" placeholder="请输入系统启动散热温度" />
				</view>
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check11')">
						<checkbox :checked="checkList.check11" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>系统停止散热温度</text>
					<input v-model="boxForm['06010017']" class="uni-input" type="digit"
						@input="onKeyInput($event,'06010017')" placeholder="请输入系统停止散热温度" />
				</view>
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check12')">
						<checkbox :checked="checkList.check12" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>启动整柜加热温度</text>
					<input v-model="boxForm['06010018']" class="uni-input" type="digit"
						@input="onKeyInput($event,'06010018')" placeholder="请输入启动整柜加热温度" />
				</view>
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check13')">
						<checkbox :checked="checkList.check13" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>停止整柜加热温度</text>
					<input v-model="boxForm['06010019']" class="uni-input" type="digit"
						@input="onKeyInput($event,'06010019')" placeholder="请输入停止整柜加热温度" />
				</view>
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check14')">
						<checkbox :checked="checkList.check14" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>启动单仓加热温度</text>
					<input v-model="boxForm['06010020']" class="uni-input" type="digit"
						@input="onKeyInput($event,'06010020')" placeholder="请输入启动单仓加热温度" />
				</view>
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check15')">
						<checkbox :checked="checkList.check15" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>停止单仓加热温度</text>
					<input v-model="boxForm['06010021']" class="uni-input" type="digit"
						@input="onKeyInput($event,'06010021')" placeholder="请输入停止单仓加热温度" />
				</view>
				
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check16')">
						<checkbox :checked="checkList.check16" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>输入连接器阻抗阈值</text>
					<input v-model="boxForm['06010064']" class="uni-input" type="number"
						@input="onKeyInput($event,'06010064')" placeholder="输入连接器阻抗阈值" />
				</view>
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check17')">
						<checkbox :checked="checkList.check17" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>输出连接器阻抗阈值</text>
					<input v-model="boxForm['06010065']" class="uni-input" type="number"
						@input="onKeyInput($event,'06010065')" placeholder="输出连接器阻抗阈值" />
				</view>
				
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check18')">
						<checkbox :checked="checkList.check18" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>从柜数量</text>
					<input v-model="boxForm['06010012']" class="uni-input" type="number"
						@input="onKeyInput($event,'06010012')" placeholder="请输入从柜数量" />
				</view>
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check19')">
						<checkbox :checked="checkList.check19" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>格口数量</text>
					<input v-model="boxForm['06010013']" class="uni-input" type="number"
						@input="onKeyInput($event,'06010013')" placeholder="请输入格口数量" />
				</view>
				
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check20')">
						<checkbox :checked="checkList.check20" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>满电阈值(%)</text>
					<input v-model="boxForm['06010031']" class="uni-input" type="digit"
						@input="onKeyInput($event,'06010031')" placeholder="请输入满电阈值" />
				</view>
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check21')">
						<checkbox :checked="checkList.check21" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>设备SN码</text>
					<input v-model="boxForm['06010025']" class="uni-input" placeholder="请输入设备SN码" />
				</view>
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check22')">
						<checkbox :checked="checkList.check22" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>有序充电</text>
					<input v-model="boxForm['06010027']" class="uni-input" placeholder="请输入有序充电" />
				</view>
				
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check23')">
						<checkbox :checked="checkList.check23" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>广告链接</text>
					<input v-model="boxForm['06010026']" class="uni-input" placeholder="请输入广告链接" />
				</view>
				
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check24')">
						<checkbox :checked="checkList.check24" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>电池容量区分</text>
					<switch color="#51b7b9" @change="switchChange($event,'06010028')" :checked="boxForm['06010028']"
						style="transform:scale(0.7)" />
				</view>
				<!-- <view class="param-one">
				<checkbox-group @change="checkboxChange($event,'check19')">
					<checkbox :checked="checkList.check19" color="#51b7b9" style="transform:scale(0.7)" />
				</checkbox-group>
				<text>邮政密码</text>
				<input v-model="boxForm['06010029']" class="uni-input" placeholder="请输入邮政密码" />
			</view> -->
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check25')">
						<checkbox :checked="checkList.check25" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>管理员密码</text>
					<input v-model="boxForm['06010030']" @input="onPasswordInput('06010030')" class="uni-input" placeholder="请输入管理员密码" />
				</view>
				
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check26')">
						<checkbox :checked="checkList.check26" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>喇叭音量设置</text>
					<slider class="sliders" :value="boxForm['06010032']" @change="sliderChange" min="0" max="100"
						show-value block-size="10" block-color="#51b7b9" />
				</view>
			</view>

			<!-- 充电堆参数 -->
			<view v-else-if="equipTypeCode == 'CS'">
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check1')">
						<checkbox :checked="checkList.check1" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>总功率限制值</text>
					<input v-model="boxForm2['07010007']" class="uni-input" placeholder="请输入总功率限制值" />
				</view>
				<view class="param-one">
					<checkbox-group @change="checkboxChange($event,'check2')">
						<checkbox :checked="checkList.check2" color="#51b7b9" style="transform:scale(0.7)" />
					</checkbox-group>
					<text>充电堆类型</text>
					<uni-data-select class="sliders" placeholder="请选择充电堆类型" v-model="boxForm2['07010008']"
						:localdata="CHARGING_TYPE"></uni-data-select>
				</view>
			</view>

			<view class="search_btns">
				<button type="primary" size="mini" @click="isSetting"
					v-if="permission('applet:batchparam:setting')">批量设置</button>
			</view>
		</view>

		<view class="table-title" v-if="nofoundList.length>0" style="color: red;">
			未搜索到的设备列表
		</view>
		<uni-list class="nofoundList" v-if="nofoundList.length>0">
			<uni-list-item title="编码">
				<template slot="footer">
					<text style="font-size: 24rpx;">复制</text>
				</template>
			</uni-list-item>
			<uni-list-item v-for="(item,index) in nofoundList" :key="index" :title="item">
				<template slot="footer">
					<text class="iconfont icon-copy" @click="isCopy(item)"></text>
				</template>
			</uni-list-item>
		</uni-list>
		<view class="table-title">
			<view class="head-title">柜列表<span class="isAllow" v-if="tableData.length>0">（选中设备即为当前页设备）</span></view>
			<view v-if="tableData.length>0" class="isAllow tips">注：设备编码为红色文字的代表当前设备不可用</view>
		</view>

		<view class="table" v-if="tableData.length>0">
			<view class="tr">
				<view class="th">
					<checkbox value="false" style="transform:scale(.85)" :checked="isCheckedAll" @click="checkAll" />
				</view>
				<view class="th width-text"></view>
				<view class="th"></view>
				<view class="th width-text">操作</view>
			</view>
			<view class="tr" v-for="(item,index) in tableData" :key="index">
				<view class="td indexs">
					<checkbox style="transform:scale(.85)" :checked="item.checked" @click="checkboxClick(index)" />
				</view>
				
				<view class="td width-text indexs">
					<view>序号</view>
					<view class="bordert">编码</view>
					<view class="bordert">ID</view>
					<view class="bordert" v-if="item.resultCode">结果</view>
					<view class="bordert" v-if="item.resultCode&&item.resultCode !=200">描述</view>
				</view>
				<view class="td">
					<view>{{index+1}}</view>
					<view :class="['status','bordert',{'isAllow':!item.isAllowOperate}]">{{item.code?item.code:""}}
					</view>
					<view class="bordert">{{item.id}}</view>
					<view class="bordert" v-if="item.resultCode">
						{{item.resultCode == 200 ?'成功':'失败'}}
					</view>
					<view class="bordert" v-if="item.resultCode&&item.resultCode !=200">
						{{item.resultMessage}}
					</view>
				</view>
				<view class="td width-text indexs">
					<view class="iconfont icon-copy" v-if="item.code" @click="isCopy(item.code)"></view>
					
					<view 
						 v-if="permission('applet:batchparam:setting') && item.resultCode&&item.resultCode !=200">
						<uni-icons type="gear" size="24" color="#999999" @click="resendParam(index)">
						</uni-icons>
					</view>
				</view>
			</view>
		</view>
		<uni-pagination class="pagination" v-if="tableData.length>0" @change="changePage()" :pageSize="size" :current="page" :total="total"
			:show-icon="true" prev-text="前一页" next-text="后一页" />
			
		<view class="nodata" v-if="tableData.length == 0">
			<image class="empty_img" src="/static/images/empty.png" mode="widthFix"></image>
			<view>暂无数据</view>
		</view>
	</view>
</template>

<script>
	import {
		equipment,
		partType
	} from "@/api/my.js";
	import {
		removeNullUndefined,
		doCopy,
		unique
	} from "@/common/index.js";

	import {
		getLockOption,
		batteryIsOn,
		CHARGING_TYPE,mainControlVersion
	} from "@/common/config.js";
	import {
		permission
	} from "@/common/permission.js";
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				getLockOption: getLockOption,
				batteryIsOn: batteryIsOn,
				CHARGING_TYPE: CHARGING_TYPE,
				mainControlVersion:mainControlVersion,
				searchData: {
					codes: "",
				},
				tableData: [],
				// 每页数据量
				size: 30,
				// 当前页
				page: 1,
				total:0,
				
				operateForm: {
					deviceName: "",
					deviceSecret: "",
					password: "",
					port: "",
					productKey: "",
					url: "",
					username: "",
				},
				isCheckedAll: false, //全选
				nofoundList: [], //未找到code列表

				boxForm: {
					"06010014": 0,
					"06010015": 0,
					"06010023": 0,
					"06010007": undefined,
					"06010009": undefined,
					"06010011": undefined,
					"06010022": undefined,
					
					"06010006":undefined,
					
					"06010024": undefined,
					"06010016": undefined,
					"06010017": undefined,
					"06010018": undefined,
					"06010019": undefined,
					"06010020": undefined,
					"06010021": undefined,
					
					"06010064": undefined,
					"06010065": undefined,
					"06010012": undefined,
					"06010013": undefined,
					
					"06010031": undefined,
					"06010025": undefined,
					"06010027": undefined,
					"06010026":undefined,
					"06010028": undefined,
					// "06010029": undefined,
					"06010030": undefined,
					"06010032": 0,
					"06010008": 0,
				},
				// 充电堆参数
				boxForm2: {
					"07010007": undefined,
					"07010008": undefined,
				},
				checkList: {
					check1: false,
					check2: false,
					check3: false,
					check4: false,
					check5: false,
					check6: false,
					check7: false,
					check8: false,
					check9: false,
					check10: false,
					check11: false,
					check12: false,
					check13: false,
					check14: false,
					check15: false,
					check16: false,
					check17: false,
					check18: false,
					check19: false,
					check20: false,
					check21: false,
					check22: false,
					check23: false,
					check24: false,
					check25: false,
					check26: false,
				},
				equipIds: [], //所选设备ids
				checkedParam: {}, //选中的参数信息
				permission: permission,
			}
		},
		computed: {
			...mapState(['equipTypeCode'])
		},
		methods: {
			getDataList() {
				let param = {
					...this.searchData
				};
				if (param.codes) {
				    param.codes = param.codes.split("\n").filter(item=>item);
				}
				if(param.codes&&param.codes.length ==1){
					param.code = param.codes[0];
				    delete param.codes;
				}

				this.nofoundList = [];
				if (param.codes&&param.codes.length > 30) {
					this.$Toast.none('最多30个设备号～');
					return;
				}
				this.$Toast.loading('加载中~');
				equipment('/version/list', 'post', {
					...removeNullUndefined(Object.assign(param, {
						pageNum: this.page,
						pageSize: this.size,
						equipTypeCode: this.equipTypeCode
					}))
				}).then(res => {
					if (res.code == 200) {
						this.tableData = res.data;
						this.tableData.forEach(item => item.checked = false);
						this.isCheckedAll = false;
						
						this.total = +res.total;

						// 查找未搜索到的设备code
						if(param.codes){
							this.nofoundList = param.codes.filter(item => !this.tableData.some(ele => ele.code
							.toLowerCase() ==
							item.toLowerCase()));
						}else if(param.code){
							this.nofoundList = this.tableData.length ==0?[param.code]:[];
						}
					}
				}).finally(() => uni.hideLoading());
			},
			
			// 分页
			changePage(e) {
				this.page = e.current;
				this.getDataList();
			},

			// 搜索
			doSearch() {
				let param = {
					...this.searchData
				};
				
				if (param.codes) {
				    param.codes = param.codes.split("\n").filter(item=>item);
				}
				if (param.codes.length ==0) {
					this.$Toast.none('请输入柜号');
					return;
				}
				this.getDataList();
			},
			// 复制
			isCopy(item) {
				doCopy(item);
			},
			//限制输入特殊字符
			keyUp(e) {
				let str = e.target.value.replace(
					/[`~!@#$%^&*()_\-+=<>?:"{}|.\;'\\[\]·~！@#￥%……&*（）——\-+={}|《》？：“”【】、；‘’，。、]/g,
					""
				);
				e.target.value = str;
				this.searchData.codes = str;
			},
			// 只能输入汉字、英文、数字
			keyInput(e) {
				let str = e.target.value.replace(/[^\a-\z\A-\Z0-9\n/]/g, "");
				e.target.value = str;
				this.searchData.codes = str;
			},
			keyBlur() {
				let codes = JSON.parse(JSON.stringify(this.searchData.codes));
				codes = unique(codes.split("\n"));
				this.searchData.codes = codes.join('\n');
			},
			onPasswordInput(type){
				setTimeout(() => {
					this.boxForm[type] = this.boxForm[type].replace(/\s+/g, '');
					this.boxForm[type] = this.boxForm[type].replace(/[\u4E00-\u9FA5]/g,'')
				}, 10)
			},
			checkboxClick(e) {
				let check = !this.tableData[e].checked;
				this.$set(this.tableData[e], 'checked', check);
				let checkList = this.tableData.filter(item => item.checked);
				if (checkList.length == this.tableData.length) {
					this.isCheckedAll = true;
				} else {
					this.isCheckedAll = false;
				}
			},
			checkAll() {
				this.isCheckedAll = !this.isCheckedAll;
				if (this.isCheckedAll) {
					this.tableData.forEach(item => item.checked = true);
				} else {
					this.tableData.forEach(item => item.checked = false);
				}
			},
			// 参数设置成功回调
			paramResult(e) {
				this.tableData = e;
			},
			// 参数重设
			resendParam(e) {
				this.tableData.forEach(item => item.checked = false);
				this.checkboxClick(e);
				this.isSetting();
			},
			switchChange(e, key) {
				let value = e.detail.value;
				this.boxForm[key] = value ? "1" : "0";
			},
			checkboxChange(e, key) {
				let value = e.detail.value;
				let check = value.length > 0 ? true : false;
				this.$set(this.checkList, key, check);
			},
			sliderChange(e) {
				let value = e.detail.value;
				this.$set(this.boxForm, '06010032', value);
			},
			isSetting() {
				let that = this;
				let isChecked = {};
				if (this.equipTypeCode == 'CS') { //充电堆
					Object.values(this.checkList).map((item, index) => {
						Object.keys(this.boxForm2).filter((pp, inx) => {
							if (item && index == inx) {
								isChecked[pp] = this.boxForm2[pp];
							}
						});
					});
				} else if (this.equipTypeCode == 'EC') { //换电柜
					Object.values(this.checkList).map((item, index) => {
						Object.keys(this.boxForm).filter((pp, inx) => {
							if (item && index == inx) {
								isChecked[pp] = this.boxForm[pp];
							}
						});
					});
				}

				this.checkedParam = isChecked;
				this.equipIds = this.tableData.filter(item => item.checked).map(p => {
					return p.id
				});
				let onlineList = this.tableData.filter(item => item.checked && item.isAllowOperate); //可操作设备
				if (this.checkList.check5) {
					isChecked['06010008'] = this.boxForm['06010008'];
				}
				if (this.tableData.length == 0) {
					this.$Toast.none('暂无设备，请先搜索~');
					return;
				} else if (this.equipIds.length == 0) {
					this.$Toast.none('请选择需要设置的设备');
					return;
				} else if (Object.keys(isChecked).length == 0) {
					this.$Toast.none("请勾选需要设置的参数！");
					return;
				} 
				
				else if (this.equipIds.length > 0 && onlineList.length == 0) {
					this.$Toast.none('设备离线/禁用不可操作！');
					return;
				} 
				else if (
					!Object.values(isChecked).every((item) => item || item == "0")
				) {
					this.$Toast.none("请设置已勾选的参数值！");
					return;
				} 
				else {
					let msg = '';
					if (onlineList.length < this.equipIds.length) { //选中设备包含离线
						msg = "离线/禁用设备不可操作，已自动过滤！"
					}
					uni.showModal({
						title: '提示',
						content: this.equipIds.length == 1 ? `${msg}确认要设置参数信息吗？` : `${msg}确认要批量设置参数信息吗？`,
						success(res) {
							if (res.confirm) {
								that.dividerGroup();
							}
						}
					})
				}
			},

			dividerGroup() {
				let that = this;
				let arr = this.tableData.filter(item => item.checked && item.isAllowOperate).map(pp => {
					return pp.id
				}); //过滤选中且可操作项
				
				let arrr = [];
				let result = arr.reduce(function(pre, item, index, arr) {
					let begin = index * 5;
					let end = begin + 5;
					let res = arr.slice(begin, end);
					if (res.length != 0) {
						arrr[index] = res;
					}
					return arrr;
				}, []);

				this.$Toast.loading('设置中~');
				// 5个一组,每次下发5个
				(function(arr) {
					let i = 0,
						length = result.length;
					(function a() {
						let timer = setTimeout(function() {
							let lng = i == length - 1 ? true : false;
							that.doSetting(result[i++], lng);
							i < length && a();
						}, 300);
					}())
				}(result));
			},
			// 设置参数
			doSetting(arr, isLast) {
				let datas = [];
				for (const key in this.checkedParam) {
					datas.push({
						id: key,
						value: this.checkedParam[key]
					});
				}
				let params = {
					entitys: datas,
				};
				// isLast 是否最后一组
				for (let i = 0; i < arr.length; i++) {
					params.equipId = arr[i];
					equipment("/operate/param/write", "post", params)
						.then((res) => {
							let inx = this.tableData.findIndex(item => item.id == arr[i]);
							this.$set(this.tableData[inx], 'resultCode', res.code);
							this.$set(this.tableData[inx], 'resultMessage', res.message);
							this.$emit('paramResult', this.tableData)
						})
						.finally((fina) => {
							if (isLast && i == arr.length - 1) {
								this.$Toast.none('参数设置完成');
								for (const key in this.checkList) {
									this.$set(this.checkList, key, false)
								}

								this.isCheckedAll = false;
								this.tableData.forEach(item => item.checked = false);
							}
						}).catch(err => {
							let inx = this.tableData.findIndex(item => item.id == arr[i]);
							this.$set(this.tableData[inx], 'resultCode', err.code);
							this.$set(this.tableData[inx], 'resultMessage', err.message);
							this.$emit('paramResult', this.tableData)
						});;
				}
			},
			onKeyInput(e, key) {
				let value = e.target.value.replace(/\D/g, '');
				this.boxForm[key] = value;
			},
		},
	}
</script>

<style lang="scss" scoped>
	@import "@/static/css/common";
	@import "@/static/iconfont.css";
	@import "@/static/css/table";

	.content {
		padding: 10rpx 20rpx;
		box-sizing: border-box;
	}

	.search_btns {
		text-align: right;
		margin-top: 10rpx;

		button {
			background-color: #51b7b9;
		}
	}

	.textareas {
		box-sizing: border-box;
		width: 100%;
		border: 2rpx solid #E5E5E5;
		padding: 10rpx;
		word-break: break-all;
		word-wrap: break-word;
	}

	.table-title {
		margin: 0 0 10rpx;
		color: #333333;
		font-size: 32rpx;
		font-weight: 500;
	}

	.table {
		width: 100%;
		border-radius: 8rpx;
		display: table;
		border: 2rpx solid #dfdfdf;
		border-collapse: collapse;
		color: #333333;
		font-size: 28rpx;
		margin-bottom: 120rpx;
	}

	.th {
		text-align: center;
		padding: 10rpx 0;
		font-weight: bolder;
		display: table-cell;
		border: 2rpx solid #dfdfdf
	}

	.td {
		text-align: center;
		background: #FFFFFF;
		padding: 10rpx 0;
		display: table-cell;
		border: 2rpx solid #dfdfdf;

		view {
			min-height: 50rpx;
		}
	}

	.tr {
		display: table-row;
		border: 2rpx solid #dfdfdf;
	}

	.indexs {
		vertical-align: middle;
	}

	.width-text {
		width: 76rpx;
	}

	.bordert {
		border-top: 2rpx solid #dfdfdf;
		padding-top: 10rpx;
		margin-top: 10rpx;
	}

	.versions {
		padding: 0 10rpx;
		text-align: left;
	}

	.nodata {
		margin-top: 10%;
		padding-bottom: 40rpx;
	}

	.status {
		@include flexLayout(center, center);

		.isonline {
			width: 30rpx;
		}
	}

	/deep/ .uni-list-item__container {
		padding: 16rpx 20rpx;
	}

	.param-content {
		padding: 0 10rpx 0;

		.param-one {
			line-height: 92rpx;
			@include flexLayout(center, flex-start);
			border-bottom: 2rpx solid #E5E5E5;
			font-size: 28rpx;
			color: #333333;

			text {
				width: 252rpx;
				text-align: right;
				margin-right: 20rpx;
			}

			.sliders {
				width: calc(100% - 250rpx);
			}
		}

		.search_btns {
			text-align: right;
			margin: 10rpx 0 0;

			button {
				background-color: #51b7b9;
			}
		}
	}

	.isAllow {
		color: red;
	}

	.tips {
		font-size: 28rpx;
		margin-top: 10rpx;
	}
	.pagination {
		width: 100%;
		position: fixed;
		bottom: 20rpx;
		left: 0;
		background: #FFFFFF;
		padding: 20rpx 0;
	}
	
	.icon-copy {
		font-size: 36rpx;
		color: #666666;
	}
</style>